﻿using System;
using System.Collections;
using System.Data;
using Lib.Data;
using Lib.Utils;


namespace SysObj
{
    public class L_KhachHang : Lib.Bases.BaseClass
    {
        #region Prop
        public System.Int32 IdKhachHang
        {
            get;
            set;
        }

        public System.String MaKhachHang
        {
            get;
            set;
        }

        public System.String TenKhachHang
        {
            get;
            set;
        }

        public System.String DiaChi
        {
            get;
            set;
        }

        public System.String Fax
        {
            get;
            set;
        }

        public System.String MST
        {
            get;
            set;
        }

        public System.String DienThoai1
        {
            get;
            set;
        }

        public System.String DienThoai2
        {
            get;
            set;
        }

        public System.String GhiChu
        {
            get;
            set;
        }

        public System.Int32 IdLoai
        {
            get;
            set;
        }

        public System.Int32 IdNhom
        {
            get;
            set;
        }

        #endregion

        #region  Constructors
        public L_KhachHang()
        {
            m_DataLayer = new Lib.Data.DataLayer();
        }
        #endregion

        #region Methods
        public override void ResetData()
        {
            IdKhachHang = 0;
            MaKhachHang = string.Empty;
            TenKhachHang = string.Empty;
            DiaChi = string.Empty;
            Fax = string.Empty;
            MST = string.Empty;
            DienThoai1 = string.Empty;
            DienThoai2 = string.Empty;
            GhiChu = string.Empty;
            IdLoai = 0;
            IdNhom = 0;
        }

        public void ReadData()
        {
            DataTable dt = new DataTable();
            try
            {
                dt = m_DataLayer.ExecDataTable("SP_L_KhachHang", " Command,IdKhachHang", "LoadData", IdKhachHang);
                this.ResetData();
                if (dt == null || dt.Rows.Count <= 0)
                    return;
                this.FillData(dt.Rows[0]);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public override DataTable LoadData()
        {
            return m_DataLayer.ExecDataTable("SP_L_KhachHang", "Command", "GetList");
        }

        public override void FillData(DataRow row)
        {
            ResetData();
            if (row.Table.Columns.Contains("IdKhachHang"))
                IdKhachHang = Lib.Data.ValueType.GetValue(row["IdKhachHang"], IdKhachHang);
            if (row.Table.Columns.Contains("MaKhachHang"))
                MaKhachHang = Lib.Data.ValueType.GetValue(row["MaKhachHang"], MaKhachHang);
            if (row.Table.Columns.Contains("TenKhachHang"))
                TenKhachHang = Lib.Data.ValueType.GetValue(row["TenKhachHang"], TenKhachHang);
            if (row.Table.Columns.Contains("DiaChi"))
                DiaChi = Lib.Data.ValueType.GetValue(row["DiaChi"], DiaChi);
            if (row.Table.Columns.Contains("Fax"))
                Fax = Lib.Data.ValueType.GetValue(row["Fax"], Fax);
            if (row.Table.Columns.Contains("MST"))
                MST = Lib.Data.ValueType.GetValue(row["MST"], MST);
            if (row.Table.Columns.Contains("DienThoai1"))
                DienThoai1 = Lib.Data.ValueType.GetValue(row["DienThoai1"], DienThoai1);
            if (row.Table.Columns.Contains("DienThoai2"))
                DienThoai2 = Lib.Data.ValueType.GetValue(row["DienThoai2"], DienThoai2);
            if (row.Table.Columns.Contains("GhiChu"))
                GhiChu = Lib.Data.ValueType.GetValue(row["GhiChu"], GhiChu);
            if (row.Table.Columns.Contains("IdLoai"))
                IdLoai = Lib.Data.ValueType.GetValue(row["IdLoai"], IdLoai);
            if (row.Table.Columns.Contains("IdNhom"))
                IdNhom = Lib.Data.ValueType.GetValue(row["IdNhom"], IdNhom);
        }

        public override void OnUpdate()
        {
            Hashtable output = null;
            string s_ParamName = "";
            object[] o_ParamValue = null;
            try
            {
                Lib.Data.ParamHolder.ClearAll();
                Lib.Data.ParamHolder.AddParam("Command", "Update");
                Lib.Data.ParamHolder.AddParam("IdKhachHang", IdKhachHang);
                Lib.Data.ParamHolder.AddParam("MaKhachHang", MaKhachHang);
                Lib.Data.ParamHolder.AddParam("TenKhachHang", TenKhachHang);
                Lib.Data.ParamHolder.AddParam("DiaChi", DiaChi);
                Lib.Data.ParamHolder.AddParam("Fax", Fax);
                Lib.Data.ParamHolder.AddParam("MST", MST);
                Lib.Data.ParamHolder.AddParam("DienThoai1", DienThoai1);
                Lib.Data.ParamHolder.AddParam("DienThoai2", DienThoai2);
                Lib.Data.ParamHolder.AddParam("GhiChu", GhiChu);
                Lib.Data.ParamHolder.AddParam("IdLoai", IdLoai);
                Lib.Data.ParamHolder.AddParam("IdNhom", IdNhom);
                Lib.Data.ParamHolder.GetParams(ref s_ParamName, ref o_ParamValue);
                m_DataLayer.ExecNonQuery("SP_L_KHACHHANG", s_ParamName, ref output, o_ParamValue);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public override void OnDelete()
        {
            string s_ParamName = "";
            object[] o_ParamValue = null;
            try
            {
                Lib.Data.ParamHolder.ClearAll();
                Lib.Data.ParamHolder.AddParam("Command", "Delete");
                Lib.Data.ParamHolder.AddParam("IdKhachHang", IdKhachHang);
                Lib.Data.ParamHolder.GetParams(ref s_ParamName, ref o_ParamValue);
                m_DataLayer.ExecNonQuery("SP_L_KHACHHANG", s_ParamName, o_ParamValue);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}
